// var Vue = require('vue')
import Vue from 'vue'
import App from './app_index.vue'
import router from './router_index'
import VueAsyncData from 'vue-async-data'
import VueResource from 'vue-resource'
import axios from 'axios'
import ElementUI from 'element-ui'
import VueCommon from './VueCommon.js'
//123
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(VueResource)
Vue.use(VueAsyncData)
Vue.use(ElementUI)


Vue.prototype.msgboxEx = function(msg, arg) {
    if (typeof(arg) == 'undefine') { arg = 'info' }
    Vue.prototype.$message({
        showClose: true,
        message: msg,
        type: arg
    });
}
Vue.prototype.msgbox = function(msg) {
    if (typeof(arg) == 'undefine') { arg = 'success' }
    Vue.prototype.$message({
        showClose: true,
        message: msg,
        type: arg
    });
}
Vue.prototype.ajaxGet = function(url, params, success, fail) {
    axios.get(url, params)
        .then(function(response) {
            success(response)
            console.log(response);
        })
        .catch(function(error) {
            fail(error)
        });
}
Vue.prototype.ajaxPost = function(url, params, success, fail) {
    axios.post(url, params)
        .then(function(response) {
            success(response)
            console.log(response);
        })
        .catch(function(error) {
            fail(error)
        });
}
Vue.prototype.isEmpty = function(str) {
    if (str === null || str === undefined || str === '') {
        return true
    }
    return false
}





//获取当前页面路由信息
router.afterEach(function(transition) {
    console.log("当前路由参数")
    console.log(transition)
})

router.beforeEach(function(to, from, next) {  
    if (to.meta.requireAuth == true) {
        if (VueCommon.isLogin() == false) {
             window.location.href="/index.html#/login"
             return
        }
    }else{
        if (to.path =='/login') {
            if (VueCommon.isLogin() == true) {
                window.location.href="/main.html#/"
                return
            }
        }
    }
    next();  
})





// filter
var filter = require('./filter')

Object.keys(filter).forEach(function(k) {
    Vue.filter(k, filter[k])
});



//directive
// var directive = require('./directive')

// Object.keys(directive).forEach(function(k) {
//   Vue.directive(k, directive[k]);
// });



// router.start(App, 'app')
// const app = new Vue({
//   router
// }).$mount('#app4')

new Vue({
    router,
    render: h => h(App)
}).$mount('#app');
